const app = getApp();
Page({
  data: {
    tabIndex:0,
    homeData:{},
    tabbar: {
      textColor: "#999",
      selectedColor: "#108ee9",
      backgroundColor: "red",
      borderStyle: "#d5d5d5",
      items: [
        {
          pagePath: "/components/home/home",
          name: "首页",
          icon: "/image/home.png",//未选icon
          activeIcon: "/image/home-act.png"//选中icon
        },
        {
          pagePath: "/components/chosen/chosen",
          name: "精选",
          icon: "/image/chosen.png",
          activeIcon: "/image/chosen-act.png"
        },
        {
          pagePath: "/components/service/service",
          name: "客服",
          icon: "/image/service.png",
          activeIcon: "/image/service-act.png"
        },
        {
          pagePath: "/components/my/my",
          name: "我的",
          icon: "/image/my.png",
          activeIcon: "/image/my-act.png"
        },         
      ],
      position: "bottom"
    },
    systemInfo:{},
  },
  onLoad() {
    my.setNavigationBar({
      backgroundColor:"#01c8bf",
    });
    this._getSystemInfo();
    this._initData();
  },
  changeTab:function(e){
    const {currentTarget} = e;
    const {tabIndex} = currentTarget.dataset;
    this.setData({tabIndex:tabIndex});
    const name = this.data.tabbar.items[tabIndex].name;
    my.setNavigationBar({
      title:name==="首页"?"宜人租机":name,
    });
  },

  onPullDownRefresh() {
    console.log('onPullDownRefresh', new Date());
    this._initData();
  },
  stopPullDownRefresh() {
    my.stopPullDownRefresh({
      complete(res) {
       
      }
    })
  },

  // 获取初始化数据
  _initData(){
    // 获取后端数据
 
    // this.setData({
    //   // 初始化首页
    //   homeData:{
    //     // 走马灯
    //     swiper:[
    //       {id:1,image:"/image/temp/a.jpg",url:""},
    //       {id:1,image:"/image/temp/b.jpg",url:""},
    //     ],
    //     // 商品分类
    //     types:[
    //       {id:1,title:"苹果",subTitle:"描述",product:[{id:1,image:"/image/temp/product.jpg",tit:"我是商品名称苹果"},{id:2,image:"/image/temp/product.jpg",tit:"我是商品名称"},{id:3,image:"/image/temp/product.jpg",tit:"我是商品名称"},{id:2,image:"/image/temp/product.jpg",tit:"我是商品名称"},{id:3,image:"/image/temp/product.jpg",tit:"我是商品名称"}]},
    //       {id:1,title:"华为",subTitle:"描述",product:[{id:1,image:"/image/temp/product.jpg",tit:"我是商品名称华为"},{id:2,image:"/image/temp/product.jpg",tit:"我是商品名称"}]},
    //       {id:1,title:"小米",subTitle:"描述",product:[{id:1,image:"/image/temp/product.jpg",tit:"我是商品名称小米"},{id:2,image:"/image/temp/product.jpg",tit:"我是商品名称"}]},
    //       {id:1,title:"vivo",subTitle:"描述",product:[{id:1,image:"/image/temp/product.jpg",tit:"我是商品名称vivo"},{id:2,image:"/image/temp/product.jpg",tit:"我是商品名称"}]},
    //     ],
    //     // 商品推荐
    //     recommend:[
    //       {
    //         id:1,
    //         tit:"我是商我是商品我是商品品",
    //         price:"100",
    //         unit:"天",
    //         image:"/image/temp/product.jpg"
    //       },
    //       {
    //         id:1,
    //         tit:"我是商品",
    //         price:"100",
    //         unit:"天",
    //         image:"/image/temp/product.jpg"
    //       },
    //       {
    //         id:1,
    //         tit:"我是商品",
    //         price:"100",
    //         unit:"天",
    //         image:"/image/temp/product.jpg"
    //       }
    //     ],
    //     btns:[
    //       {url:"",tit:"爆款专区",image:"/image/btn-1.png"},
    //       {url:"",tit:"爆款专区",image:"/image/btn-2.png"},
    //       {url:"",tit:"爆款专区",image:"/image/btn-3.png"},
    //       {url:"",tit:"爆款专区",image:"/image/btn-4.png"},
    //       {url:"",tit:"爆款专区",image:"/image/btn-5.png"},
    //     ]
    //   }
    // });
    setTimeout(() => this.stopPullDownRefresh(), 2000);
  },



  // 系统信息
  _getSystemInfo() {
    my.getSystemInfo({
      success: (res) => {
        this.setData({
          systemInfo: res
        })
      }
    })
  },
});
